"use strict";
cc._RF.push(module, 'ee04aGPVp9MH4rcSBcggbjz', 'timeShow');
// Script/timeShow.js

"use strict";

var _backgrould = require("./backgrould");

var _backgrould2 = _interopRequireDefault(_backgrould);

var _allVariable = require("./allVariable");

var _allVariable2 = _interopRequireDefault(_allVariable);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

cc.Class({
    extends: cc.Component,

    properties: {
        timesprite: cc.Node,
        timeArray: [cc.SpriteFrame],
        timeCount: cc.Integer,
        countDownArray: [cc.Node],
        endGameView: cc.Node,
        noendGameView: cc.Node,
        showHubProjess: cc.Node,
        backGroundJs: _backgrould2.default,
        timeBtn: cc.Node,
        SvprogressPrefab: cc.Prefab,
        endCutDown: cc.Node,
        endfinshTimes: cc.Node,
        timePropNum: cc.Integer, //时间道具数量
        cutTimeView: cc.Node,
        timeSound: {
            default: null,
            type: cc.AudioClip
        },
        unitTime: cc.Node,
        decadeTime: cc.Node,
        myTimes: 0

    },

    onLoad: function onLoad() {},


    addTimePropNumber: function addTimePropNumber() {
        var _this = this;

        if (this.timeCount > 93) {

            if (cc.isValid(this.showHubProjess)) {
                this.showHubProjess.destroy();
            }
            this.showHubProjess = cc.instantiate(this.SvprogressPrefab);
            this.backNode = cc.find("Canvas/backgroundtop");
            this.backNode.addChild(this.showHubProjess);
            this.showHubProjess.getComponent('SVProgressView').init("Time reaches the maximum limit");

            var finish = cc.callFunc(function () {

                _this.showHubProjess.destroy();
            }, this);
            var action = cc.sequence(cc.fadeIn(0.6), cc.delayTime(0.5), cc.fadeOut(1), finish);
            this.showHubProjess.runAction(action);

            return;
        }

        this.timeCount = this.timeCount + 6;

        this.unschedule(this.countDownL);

        var interval = 1;
        // 重复次数
        var repeat = this.timeCount;
        // 开始延时
        var delay = 0;

        this.schedule(this.countDownL, interval, repeat, delay);
    },

    addTimeCount: function addTimeCount() {
        var _this2 = this;

        var changebig2 = cc.scaleTo(0.2, 1.1);

        var finish = cc.callFunc(function () {

            var changesmail2 = cc.scaleTo(0.1, 1.0);
            this.timeBtn.runAction(changesmail2);
        }, this);

        var seq = cc.sequence(changebig2, finish);

        this.timeBtn.runAction(seq);

        if (this.timeCount > 88) {

            if (cc.isValid(this.showHubProjess)) {
                this.showHubProjess.destroy();
            }
            this.showHubProjess = cc.instantiate(this.SvprogressPrefab);
            this.backNode = cc.find("Canvas/backgroundtop");
            this.backNode.addChild(this.showHubProjess);
            this.showHubProjess.getComponent('SVProgressView').init("时间达到最大了");

            var _finish = cc.callFunc(function () {

                _this2.showHubProjess.destroy();
            }, this);
            var action = cc.sequence(cc.fadeIn(0.6), cc.delayTime(0.5), cc.fadeOut(1), _finish);
            this.showHubProjess.runAction(action);

            return;
        }

        if (this.timePropNum > 0) {

            this.timePropNum = this.timePropNum - 1;

            _allVariable2.default.timeCount = this.timePropNum;

            this.timeBtn.getChildByName("timePropShow").getChildByName("timePropLabel").getComponent("NumberView").setText(this.timePropNum);

            this.timeCount = this.timeCount + 10;

            this.unschedule(this.countDownL);

            var interval = 1;
            // 重复次数
            var repeat = this.timeCount;
            // 开始延时
            var delay = 0;

            this.schedule(this.countDownL, interval, repeat, delay);
        } else {

            console.log("道具数量不够");

            if (cc.isValid(this.showHubProjess)) {
                this.showHubProjess.destroy();
            }
            this.showHubProjess = cc.instantiate(this.SvprogressPrefab);
            this.backNode = cc.find("Canvas/backgroundtop");
            this.backNode.addChild(this.showHubProjess);
            this.showHubProjess.getComponent('SVProgressView').init("时间道具数量不足");

            var _finish2 = cc.callFunc(function () {

                _this2.showHubProjess.destroy();
            }, this);
            var _action = cc.sequence(cc.fadeIn(0.6), cc.delayTime(0.5), cc.fadeOut(1), _finish2);
            this.showHubProjess.runAction(_action);
        }
    },

    setTimeLoad: function setTimeLoad(timeNumber) {

        var timeArray = timeNumber.split('');

        for (var i = 0; i < timeArray.length; i++) {

            var item = cc.instantiate(this.timesprite);

            item.getComponent(cc.Sprite).spriteFrame = this.timeArray[timeArray[i]];

            this.node.addChild(item);

            this.countDownArray.push(item);
        }
    },

    stopTime: function stopTime() {

        this.unschedule(this.countDownL);
    },

    myTimeRun: function myTimeRun() {

        if (this.timeCount == 0) {
            console.log("取消自己定时器");
            return;
        }

        if (this.myTimes == 20) {
            console.log("第二等级");
            this.backGroundJs.gradeSecond();
        } else if (this.myTimes == 30) {
            console.log("第三等级");

            this.backGroundJs.gradeThree();
        } else if (this.myTimes == 40) {
            console.log("第四等级");
            this.backGroundJs.gradeFour();
        } else {
            //  console.log("第五等级")
        }
        _allVariable2.default.myPlayTimes = this.myTimes;
        console.log("当前自己玩的时间耗时", this.myTimes);
        this.myTimes = this.myTimes + 1;
    },

    countDownL: function countDownL() {

        if (this.timeCount == 0) {
            console.log("时间已经为0");
            this.unschedule(this.myTimeRun);
            cc.audioEngine.stop(this.current);
            _allVariable2.default.isEnterEndTimes = false;

            this.cutTimeView.active = false;
            this.endfinshTimes.active = false;

            if (_allVariable2.default.wawaCoinAddNumber == 0) {

                this.noendGameView.active = true;
            } else {
                this.endGameView.active = true;
            }

            this.unschedule(this.countDownL);
            this.backGroundJs.endGame();
            return;
        }

        if (this.timeCount == 1) {

            this.endCutDown.active = false;
            this.endfinshTimes.active = true;

            var changebig = cc.scaleTo(0.1, 1.2);
            var changesmall = cc.scaleTo(0.07, 1);
            var seq = cc.sequence(changebig, changesmall);
            this.endfinshTimes.runAction(seq);
        } else {
            this.endfinshTimes.active = false;
        }

        this.timeCount = this.timeCount - 1;

        if (this.timeCount <= 10 && this.timeCount >= 1) {

            this.current = cc.audioEngine.play(this.timeSound, false, 1);

            _allVariable2.default.isEnterEndTimes = true;

            this.cutTimeView.active = true;

            var opaction = cc.fadeTo(0.25, 100);

            var opaction2 = cc.fadeTo(0.25, 200);

            var opaction3 = cc.fadeTo(0.25, 100);

            var opaction4 = cc.fadeTo(0.25, 200);

            var seq = cc.sequence(opaction, opaction2, opaction3, opaction4);

            this.cutTimeView.runAction(seq);

            this.endCutDown.active = true;

            this.endCutDown.getChildByName("endTimeShow").getComponent("NumberView").setText(this.timeCount);

            var changebig = cc.scaleTo(0.1, 1.2);
            var changesmall = cc.scaleTo(0.07, 1);
            var seq = cc.sequence(changebig, changesmall);

            this.endCutDown.getChildByName("endTimeShow").runAction(seq);
        } else {

            this.cutTimeView.active = false;
            this.endCutDown.active = false;
            _allVariable2.default.isEnterEndTimes = false;
        }

        var count = this.timeCount;

        _allVariable2.default.timeNumber = this.timeCount;

        var timeArray = String(count).split('');

        var array = new Array();

        for (var i = 0; i < timeArray.length; i++) {

            array.push(this.countDownArray[i]);
        }

        for (var j = 0; j < this.countDownArray.length; j++) {

            if (j >= array.length) {
                this.countDownArray[j].active = false;
            } else {
                for (var _i = 0; _i < array.length; _i++) {
                    this.countDownArray[j].active = true;
                    array[_i].getComponent(cc.Sprite).spriteFrame = this.timeArray[timeArray[_i]];
                }
            }
        }
    },

    startTime: function startTime() {

        var interval = 1;
        // 重复次数
        var repeat = this.timeCount;
        // 开始延时
        var delay = 0;

        this.schedule(this.countDownL, interval, repeat, delay);
    },

    start: function start() {},
    init: function init(gameTimes) {

        this.timePropNum = _allVariable2.default.timeCount;

        this.unitTime.active = false;
        this.decadeTime.active = false;

        console.log("传过来的数字", gameTimes);
        this.timeCount = gameTimes;

        this.setTimeLoad(String(this.timeCount));

        var interval = 1;
        // 重复次数
        var repeat = this.timeCount;
        // 开始延时
        var delay = 0;

        this.schedule(this.countDownL, interval, repeat, delay);

        this.unschedule(this.myTimeRun);

        var myinterval = 1;

        var myrepet = 100000;

        this.myTimes = 0;

        var mydelay = 0;

        this.schedule(this.myTimeRun, myinterval, myrepet, mydelay);
    }
});

cc._RF.pop();